common={
    initCatalogueMagePage:function(){
        this.Authorization= window.localStorage.getItem("auth_token") || '';
        this.socket = io('http://1.85.32.6:50006');
        //this.socket = io('http://192.168.5.169:9099');
        // 绑定dom对象
        this.obj = {
            searchText:$('#searchText'),
        };
        // 声明全局变量
        this.vars = {
            total:"",
            path:"",
            pathth:"",
            map:"",
            map1:"",
            pathlist:"",
            mouseTool:"",
            mouseTool1:"",
            ruler1:"",
            pageNum:"",
            position:[],
            datasbcx:{
                vehicleId:"",
                vehicleNo:"",
                startTime:"",
                endTime:""
            },
            datayjjr:{
                vehicleId:"",
                vehicleNo:"",
                authenicationCode:"",
                accessPointName:"",
                userName:"",
                passWord:"",
                serverIp:"",
                tcpPort:"",
                udpPort:"",
                endTime:""
            },
            carguanzhu:{
                size:"",
                page:"",
                transType:"1,2,3"
            },
            data:{
                owersId:"",
                vehicleNo:"",
                page:"1",
                size:"10",
                transType:"1,2,3"
            },
            data1:{
                owersId:"",
                vehicleNo:"",
                page:"1",
                size:"10",
                transType:"1,2,3"
            },
            areaData:{
                page:"1",
                size:"10000",
                areaCode:"",
                center:"",
                radius:"",
                polygon:"",
                transType:"1,2,3"
            },
            guiji:{
                VehicleID:"2540",
                StartTime:"2019-08-21 03:52:37",
                EndTime:"2019-08-21 11:52:37"
            },
            shipin:{
                VehicleID:"",
                channelIds:[],
            },
            luxiang:{
                vehicleId:"",
                timeStart:"",
                timeEnd:"",
                selcetoneValue:"",
                selcettwoValue:"",
            },
            baojing:{
                vehicleNo:"",
                startTime:"",
                endTime:"",
                alarmType:"",
                page:"1",
                size:"10"
            },
            jiahu:{
                vehicleId:"",
                timeStart:"",
                timeEnd:"",
                commandCode:"",
                platformId:"",
                owersId:"",
                commandCodeName:"平台查岗请求",
            },
            gunazhu:{
                status:"",
                vehicleId:""
            },
            guanzhuche:[],
            datareaslut:[],
            markers:[],
            dataAttrmt:[],//marker 轨迹查看
        };
        this.map();
        this.carSearch(this.vars.data);
        this.page(this.vars.data);
        this.carxingzheng();
        this.creatshipin();

        this.time();
        this.match();
        this.ceju();
        this.btnEvent();

        this.selectedValue();
        //this.ajaxguiji(this.vars.guiji);
        //this.creatguanzhucheliang()
    },
    carSearch:function(dataAttr){
        var self=this;
        var mapurl=http+urls.carSearch;
        self.vars.datareaslut=[];
        self.vars.markers=[];
        $.ajax({
            headers: {
                authorization: self.Authorization
            },
            contentType: "application/json;charset=utf-8",
            dataType: "json",
            data: dataAttr,
            url: mapurl,
            type: "get",
            success: function (data) {
                console.log(data);
                $(".tsearch_tableCount span").eq(0).find("em").html(data.total);
                $(".tsearch_tableCount span").eq(1).find("em").html(data.onLine);
                self.vars.tototal=parseInt(data.total/self.vars.data.size)+1;
                var attrdata=data.data;
                var datareaslut=[];
                self.vars.markers=[];
                for (var i = 0; i < attrdata.length; i++) {
                    datareaslut.push({
                        order: attrdata[i].order,
                        id: attrdata[i].id,
                        attention:attrdata[i].attention,
                        color:attrdata[i].vehicleColor,
                        position: [attrdata[i].lng, attrdata[i].lat],
                        carPi: attrdata[i].vehicleNo,
                        status:attrdata[i].status,
                        adress:attrdata[i].site,
                        transTypeName:attrdata[i].transTypeName,
                        owner:attrdata[i].owersName
                    })
                };
                self.searchcarbtn();
                self.allTable("#table",datareaslut)
                self.allMaker("#table",datareaslut);
            },
        });
        console.log(self.vars.tototal)
    },
    page:function(dataAttr){
        var self=this;
        $(".page").show();
        var mapurl=http+urls.carSearch;
        $.ajax({
            headers: {
                authorization: self.Authorization
            },
            contentType: "application/json;charset=utf-8",
            dataType: "json",
            data: dataAttr,
            url: mapurl,
            type: "get",
            success: function (data) {
                console.log(data);
                self.vars.tototal = parseInt(data.total / self.vars.data.size);
                $(".page").createPage({
                    pageNum:self.vars.tototal,
                    current:1,
                    backfun: function(e) {
                        self.vars.data.page=e.current;
                        self.vars.map.clearMap();
                        self.carSearch(self.vars.data);
                    }
                });
            }
        });
    },
    carAreaSearch:function(areadata){
        var self=this;
        var mapurl=http+urls.carArea;
        self.vars.datareaslut=[];
        self.vars.markers=[];
        $.ajax({
            headers: {
                authorization: self.Authorization
            },
            contentType: "application/json;charset=utf-8",
            dataType: "json",
            data: areadata,
            url: mapurl,
            type: "get",
            success: function (data) {
                console.log("4567",data);
                if(data.data != null){
                    $(".tsearch_tableCount span").eq(0).find("em").html(data.total);
                    $(".tsearch_tableCount span").eq(1).find("em").html(data.onLine);
                    var attrdata=data.data;
                    var datareaslut1=[];
                    self.vars.markers=[];
                    for (var i = 0; i < attrdata.length; i++) {
                        datareaslut1.push({
                            order: attrdata[i].order,
                            id:attrdata[i].id,
                            attention:attrdata[i].attention,
                            color:attrdata[i].vehicleColor,
                            position: [attrdata[i].lng, attrdata[i].lat],
                            carPi: attrdata[i].vehicleNo,
                            status:attrdata[i].status,
                            adress:attrdata[i].site,
                            transTypeName:attrdata[i].transTypeName,
                            owner:attrdata[i].owersName
                        })
                    };
                    self.allTable("#table1",datareaslut1)
                    self.allMaker("#table1",datareaslut1)
                }else{
                    JPop.alert({msg:"没有数据"})
                }
            },
        });
    },
    openMarkerajax:function(id){
        var self=this;
        var mapurl=http+urls.base;
        console.log(mapurl)
        self.vars.datareaslut=[];
        self.vars.markers=[];
        $.ajax({
            headers: {
                authorization: self.Authorization
            },
            contentType: "application/json;charset=utf-8",
            dataType: "json",
            url: mapurl+id,
            type: "get",
            success: function (data) {
                $(".tsearch_headRtitHr").html(data.vehicleNo);
                function creatid(id){
                    $(id).eq(0).find("ul li").eq(0).find(".cnf_bluecolor em").html(data.vehicleNo);
                    $(id).eq(0).find("ul li").eq(0).find(".cnf_bluecolor em").attr("data-href",data.vehicleId);
                    $(id).eq(0).find("ul li").eq(1).find("span").html(data.vehicleColor);
                    $(id).eq(0).find("ul li").eq(2).find("span").html(data.brandNameModel);
                    $(id).eq(0).find("ul li").eq(3).find("span").html(data.transType);
                    $(id).eq(0).find("ul li").eq(4).find("span").html(data.vehicleAdminOrg);
                    $(id).eq(0).find("ul li").eq(5).find("span").html(data.vehicleOrgName);
                    $(id).eq(0).find("ul li").eq(6).find("span").html(data.operationStatus);
                    $(id).eq(0).find("ul li").eq(7).find("span").html(data.operationScope);
                    $(id).eq(0).find("ul li").eq(8).find("span").html(data.operationLine);
                    $(id).eq(0).find("ul li").eq(9).find("span").html(data.pasPosition);
                    $(id).eq(0).find("ul li").eq(10).find("span").html(data.vehicleRtoln);
                    $(id).eq(0).find("ul li").eq(11).find("span").html(data.vehicleRtolnTime);
                    $(id).eq(0).find("ul li").eq(12).find("span").html(data.nationality);
                    $(id).eq(0).find("ul li").eq(13).find("span").html(data.tonnage);
                    $(id).eq(0).find("ul li").eq(14).find("span").html(data.totalQuality);
                }
                creatid(".tsearch_headbox .tsearch_headboxMain")
                function creatidtwo(id){
                    $(id).eq(1).find("ul li").eq(0).find("span").html(data.owersName);
                    $(id).eq(1).find("ul li").eq(1).find("span").html(data.areaName);
                    $(id).eq(1).find("ul li").eq(2).find("span").html(data.owersRtoln);
                    $(id).eq(1).find("ul li").eq(3).find("span").html(data.owersRtolnStatus);
                    $(id).eq(1).find("ul li").eq(4).find("span").html(data.owersMan);
                    $(id).eq(1).find("ul li").eq(5).find("span").html(data.owersPhone);
                }
                creatidtwo(".tsearch_headbox .tsearch_headboxMain")
                function creatidthree(id) {
                    $(id).eq(2).find("ul li").eq(0).find("span").html(data.platformName);
                    $(id).eq(2).find("ul li").eq(1).find("span").html(data.platformPort);
                    $(id).eq(2).find("ul li").eq(2).find("span").html(data.platformMan);
                    $(id).eq(2).find("ul li").eq(3).find("span").html(data.platformPhone);
                }
                creatidthree(".tsearch_headbox .tsearch_headboxMain")
            },
        });

    },
    opensocket:function(num,id,t,car){
        console.log("qqq",id,car);
        var self=this;
        var contannner={
            "Command": num,
            "CommandType": "track",
            "token":self.Authorization,
            "Body":{
                "id":id
            }
        }
        self.socket.emit('track', JSON.stringify(contannner));
        if(t==0) {
            self.socket.on('trackReal', function (data) {
                var datacount = JSON.parse(data);
                console.log("cheliang", datacount);
                var relax = datacount.BaseVehicle;
                var onlinecar="";
                if(relax.driverOnlineStatus==1){
                    onlinecar="在线"
                }else{
                    onlinecar="离线"
                }
                console.log()
                $("#add").html(relax.vehicleNo);
                $("#add_sj").html(relax.driverData+'\\'+onlinecar)
                $(".tsearch_list").eq(1).find("ul li").eq(0).find("span").eq(1).html(relax.driverLocationTime);
                $(".tsearch_list").eq(1).find("ul li").eq(1).find("span").eq(1).html(relax.driverOnlineTime);
                $(".tsearch_list").eq(1).find("ul li").eq(2).find("span").eq(1).find("b").eq(0).text(relax.lat);
                $(".tsearch_list").eq(1).find("ul li").eq(2).find("span").eq(1).find("b").eq(1).text(relax.lng);
                $(".tsearch_list").eq(1).find("ul li").eq(3).find("span").eq(1).find("b").eq(0).text(relax.driverSpeed);
                $(".tsearch_list").eq(1).find("ul li").eq(3).find("span").eq(1).find("b").eq(1).text(relax.dirction);
                $(".tsearch_list").eq(1).find("ul li").eq(4).find("span").eq(1).find("b").eq(0).text(relax.driverElevation);
                $(".tsearch_list").eq(1).find("ul li").eq(4).find("span").eq(1).find("b").eq(1).text(relax.driverNowMil);
                $(".tsearch_list").eq(2).find("ul li").eq(0).find("span").eq(1).find("em").text(relax.driverAmbitus);
            });
        }
    },
    ajaxguiji:function(guiji){
        var self=this;
        var table=[];
        self.socket.emit('track', JSON.stringify({
            "Command":"22",
            "CommandType":"track",
            "token":self.Authorization,
            "Body":guiji
        }));
        self.socket.on('trackHistory', function(data){
            var datacount= JSON.parse(data);
            table.push(datacount);
            var objectArraySort = function (keyName) {
                return function (objectN, objectM) {
                    var valueN = objectN[keyName]
                    var valueM = objectM[keyName]
                    if (valueN < valueM) return 1
                    else if (valueN > valueM) return -1
                    else return 0
                }
            }
            table.sort(objectArraySort('order')).reverse();
            $('#tabel_one tbody').html("");
            var tableStrMrker="";
            var position=[];
            if(table.length !=0){
                for(var i=0;i<table.length;i++){
                    for(var j=0;j<table[i].TrackItems.length;j++){
                        position.push([table[i].TrackItems[j].PosData.Longitude,table[i].TrackItems[j].PosData.Latitude])
                        tableStrMrker+="<tr>"+
                            "<td>"+(i+1)*j+"</td>"+
                            "<td>"+table[i].TrackItems[j].DataTime+"</td>"+
                            "<td>"+table[i].TrackItems[j].PosData.Longitude+"</td>"+
                            "<td>"+table[i].TrackItems[j].PosData.Latitude+"</td>"+
                            "<td>"+table[i].TrackItems[j].PosData.Speed+"</td>"+
                            "<td>"+table[i].TrackItems[j].OvrallData.CurrentMileage+"</td>"+
                            "<td>"+table[i].TrackItems[j].OvrallData.CurrentMileage+"</td>"+
                            "</tr>"
                    }
                }
            }else{
                tableStrMrker+="<tr>"+
                    "<td rowspan='7'>暂无数据</td>"
                "</tr>"
            };
            console.log(position)
            $('#tabel_one tbody').html(tableStrMrker);
            var marker1 = new AMap.Marker({
                map: self.vars.map1 ,
                icon: "https://webapi.amap.com/images/car.png",
                offset: new AMap.Pixel(-26, -13),
                autoRotation: true,
                angle:-90,
                position: position[0]
            });
            self.vars.map1.add([marker1]);

            var polyline = new AMap.Polyline({
                map: self.vars.map1,
                path: position,
                showDir:true,
                strokeColor: "#28F",  //线颜色
                strokeWeight: 6,      //线宽
            });

            var passedPolyline = new AMap.Polyline({
                map: self.vars.map1,
                strokeColor: "#AF5",  //线颜色
                strokeWeight: 6,      //线宽
            });
            self.vars.map1.setFitView();
            marker1.on('moving', function (e) {
                passedPolyline.setPath(e.passedPath);
            });
            $("#start").click(function(){
                marker1.moveAlong(position, 200)
            })
            $("#pause").click(function(){
                marker1.pauseMove();
            })
            $("#resume").click(function(){
                marker1.resumeMove();
            })
        });

    },
    gunzhuAjax:function(status,vehicleId){
        var self=this;
        var mapurlgz=http+urls.guanzhu;
        $.ajax({
            headers: {
                authorization: self.Authorization
            },
            contentType: "application/json;charset=utf-8",
            dataType: "json",
            data:{
                status:status,
                vehicleId:vehicleId
            },
            url: mapurlgz,
            type: "get",
            success: function (data) {
                console.log("4567",data);

            },
        });
    },
    creatguanzhucheliang:function(carguanzhu){
        var self=this;
        var mapurl=http+urls.guanzhulist;
        self.vars.map.clearMap();
        $.ajax({
            headers: {
                authorization: self.Authorization
            },
            contentType: "application/json;charset=utf-8",
            dataType: "json",
            data:carguanzhu,
            url: mapurl,
            type: "get",
            success: function (data) {
                console.log("1111",data);
                $(".tsearch_tableCount span").eq(0).find("em").html(data.total);
                $(".tsearch_tableCount span").eq(1).find("em").html(data.onLine);
                self.vars.tototal=parseInt(data.total/self.vars.data.size)+1;
                var attrdata=data.data;
                var datareaslut=[];
                self.vars.markers=[];
                for (var i = 0; i < attrdata.length; i++) {
                    datareaslut.push({
                        order: (i+1),
                        id: attrdata[i].id,
                        color:attrdata[i].vehicleColor,
                        position: [attrdata[i].lng, attrdata[i].lat],
                        carPi: attrdata[i].vehicleNo,
                        status:attrdata[i].status,
                        adress:attrdata[i].site,
                        transTypeName:attrdata[i].transTypeName,
                        owner:attrdata[i].owersName
                    })
                };
                self.searchcarbtn();
                self.allTable("#table",datareaslut)
                self.allMaker("#table",datareaslut);
                self.allTable("#table1",datareaslut)
                self.allMaker("#table1",datareaslut);

            },
        });
    },
    creatJiaohu:function(jiaohu){
        var self=this;
        var mapurl=http+urls.jiaohu;
        console.log(mapurl)
        self.vars.datareaslut=[];
        self.vars.markers=[];
        $.ajax({
            headers: {
                authorization: self.Authorization
            },
            contentType: "application/json;charset=utf-8",
            dataType: "json",
            data: jiaohu,
            url: mapurl,
            type: "get",
            success: function (data) {
                console.log(data);
                $('#tabel_five tbody').html("");
                var tableStrMrker="";
                if(data.length !=0){
                    for(var i=0;i<data.length;i++){
                        tableStrMrker+="<tr>"+
                            "<td>"+data[i].id+"</td>"+
                            "<td>"+data[i].commandCode+"</td>"+
                            "<td>"+data[i].sendContent+"</td>"+
                            "<td>"+data[i].sendTime+"</td>"+
                            "<td>"+data[i].ackContent+"</td>"+
                            "<td>"+data[i].ackTime+"</td>"+
                            "</tr>"
                    }
                }else{
                    tableStrMrker+="<tr>"+
                        "<td rowspan='6'>暂无数据</td>"
                    "</tr>"
                }
                $('#tabel_five tbody').html(tableStrMrker);

            },
        });
    },
    creatbaojing:function(baojingdata){
        var self=this;
        var mapurl=http+urls.baojing;
        console.log(mapurl)
        self.vars.datareaslut=[];
        self.vars.markers=[];
        $.ajax({
            headers: {
                authorization: self.Authorization
            },
            contentType: "application/json;charset=utf-8",
            dataType: "json",
            data:baojingdata,
            url: mapurl,
            type: "get",
            success: function (data) {
                console.log(data);
                $('#tabel_four tbody').html("");
                var tableStrMrker="";
                if(data.length !=0){
                    for(var i=0;i<data.length;i++){
                        tableStrMrker+="<tr>"+
                            "<td>"+data[i].creatTime+"</td>"+
                            "<td>"+data[i].alarmTime+"</td>"+
                            "<td>"+data[i].alarmStartTime+"</td>"+
                            "<td>"+data[i].alarmEndTime+"</td>"+
                            "<td>"+data[i].alarmType+"</td>"+
                            "<td>"+data[i].alarmLevel+"</td>"+
                            "<td>"+data[i].alarmStatus+"</td>"+
                            "<td>"+data[i].site+"</td>"+
                            "</tr>"
                    }
                }else{
                    tableStrMrker+="<tr>"+
                        "<td rowspan='6'>暂无数据</td>"
                    "</tr>"
                }
                $('#tabel_four tbody').html(tableStrMrker);

            },
        });
    },
    creatshipin:function(shipindata,num){
        var self=this;
        self.socket.emit('Business', JSON.stringify({
            "Command": "57",
            "CommandType": "Business",
            "token":self.Authorization,
            "Body": {
                "data":{
                    "param":[shipindata],
                    "avitemType": "0"
                }
            }}));
        self.socket.on('Business', function(data){
            var datacount= JSON.parse(data);
            console.log("123",datacount);
            var width=$(".tsearch_marker").width()*0.4-20;
            var height=($(".tsearch_marker").height()*0.6-25)*0.9*0.8;
            var fileVideo="rtmp://"+datacount.Body.serverIp+":"+datacount.Body.serverPort+"/live/"+datacount.Body.vehicleNo+"."+datacount.Body.vehicleColor+"."+num+".0."+datacount.Body.authorizeCode;
            self.creatVideo("tsearch_ssjkRain",width,height,fileVideo);
        });
    },
    carxingzheng:function(){
        var self=this;
        var mapurl=http+urls.carzheng;
        self.vars.datareaslut=[];
        self.vars.markers=[];
        $.ajax({
            headers: {
                authorization: self.Authorization
            },
            contentType: "application/json;charset=utf-8",
            dataType: "json",
            data: {
                "parentId": "-1",
            },
            url: mapurl,
            type: "get",
            success: function (data) {
                console.log(data);
                $(".tsearch_xingzhengbg ul").html();
                var str="";
                for(var i=0;i<data.length;i++){
                    str += "<li data-id='"+data[i].id+"'>"+ data[i].name+"</li>"
                }
                $(".tsearch_xingzhengbg ul").html(str);
                $(".tsearch_xingzhengbg ul li").unbind("click");
                $(".tsearch_xingzhengbg ul li").click(function(){
                    var index=$(this).index();
                    var areaId = $(this).data("id");
                    $(this).addClass("tsearch_xzactive").siblings("li").removeClass("tsearch_xzactive");
                    self.vars.map.clearMap();
                    var name=$(this).text();
                    self.creatDrawarea(name);
                    self.vars.areaData.areaCode=areaId;
                    self.vars.areaData.polygon="";
                    self.carAreaSearch(self.vars.areaData)
                })
            },
        });
    },
    match:function(){
        var self=this;
        for(var i=0;i<5;i++){
            self.vars.dataAttrmt.push({
                id: i,
                time:"2018-10-09 07:23:51",
                lat:108.939621 + Math.random() * 10 - 5,
                lng:34.343147 + Math.random() * 10 - 5,
                chesu: Math.floor(Math.random() * 89 + 100),
                lichneg: Math.floor(Math.random() * 899 + 1000),
                weizhi: "陕西省西安市雁塔区太白南路108号"
            })
        }
    },
    creatVideo:function(id,width,height,filevideo){
        var player = cyberplayer(id).setup({
            width: width,
            height: height,
            file: filevideo, // <—rtmp直播地址
            autostart: true,
            stretching: "uniform",
            volume: 100,
            controls: true,
            rtmp: {
                reconnecttime: 5,
                bufferlength: 1
            },
            ak: "976604a77e2c40fdab9cf7f054ddba12"
        });
    },
    allTable:function(id,data){
        console.log(data)
        var self=this;
        $(id).find('tbody').html("");
        var tableStr="";
        for(var i=0;i<data.length;i++){
            var mheart;
            if(data[i].attention==0){
                mheart="<span data-statu='"+data[i].attention+"'><i class='iconfont'>&#xe631;</i></span>"
            }else{
                mheart="<span data-statu='"+data[i].attention+"'><i class='iconfont cnf_red'>&#xe655;</i></span>"
            }
            tableStr+="<tr data-href='"+data[i].id+"'>"+
                "<td>"+data[i].order+"</td>"+
                "<td>"+data[i].owner+"</td>"+
                "<td>"+data[i].carPi+"</td>"+
                "<td>"+data[i].color+"</td>"+
                "<td>"+data[i].transTypeName+"</td>"+
                "<td>"+data[i].status+"</td>"+
                "<td title='"+data[i].adress+"'>"+data[i].adress+"</td>"+
                "<td>"+mheart+
                "<span title='轨迹查看'><i class='iconfont'>&#xe662;</i></span>" +
                "<span title='实时视频'><i class='iconfont'>&#xe633;</i></span>" +
                "</td>"+
                "</tr>"
        }
        $(id).find('tbody').html(tableStr);
    },
    map:function(){
        var self=this;
        self.vars.map = new AMap.Map('map', {
            resizeEnable: true,
            center: [108.948024,34.263161],
            // viewMode:'3D',
            // pitch:50,
            mapStyle:'amap://styles/darkblue'

        });
        self.vars.mouseTool = new AMap.MouseTool(self.vars.map)
        self.vars.map1 = new AMap.Map('map1', {
            resizeEnable: true,
            center: [108.948024,34.263161],
            mapStyle:'amap://styles/darkblue',

        });

    },
    allMaker:function(id,data){
        console.log(data)
        var self=this;
        for (var i = 0; i < data.length; i++) {
            if(data[i].status=="在线"){
                iconImg="img/icon_marker1.png"
            }else{
                iconImg="img/icon_marker2.png"
            }
            var marker = new AMap.Marker({
                position: data[i].position,
                map: self.vars.map,
                icon:iconImg
            });
            self.vars.markers.push(marker);
            marker.content = data[i].order;
            marker.idname = data[i].id;
            marker.carno = data[i].carPi;
            marker.num = i;
            marker.on('click', function(e){
                $(".tsearch_marker").show();
                self.moren();
                self.btnEventTab(e.target.getPosition(),e.target.idname,e.target.carno);
                self.openMarkerajax(e.target.idname);
                self.opensocket("1",e.target.idname,$(".tsearch_markerClose").attr("data-num"),e.target.carno);
                $(".tsearch_markerClose").attr("data-href",e.target.idname)
                updateMarker(e.target.getPosition())
                self.vars.map1.clearMap();
                var marker1 = new AMap.Marker({
                    map: self.vars.map1 ,
                    icon: "img/icon_marker3.png",
                    position: data[e.target.num].position
                });
                var tyu=parseFloat(e.target.content % self.vars.data.size)-1;
                if(tyu==0){
                    tyu=self.vars.data.size-1
                }
                $(id).find("tbody tr").eq(tyu).addClass("add_style").siblings("tr").removeClass("add_style");
                $(id).find("tbody").scrollTop(tyu*35);

            });
        };
        function updateMarker(position) {
            var markerContent = document.createElement("div");
            var markerImg = document.createElement("img");
            markerImg.className = "markerlnglat";
            markerImg.src = "img/icon_marker3.png";

            markerContent.appendChild(markerImg);

            marker.setContent(markerContent); //更新点标记内容
            marker.setPosition(position); //更新点标记位置
        };
        $(id).find("tbody tr").click(function(){
            var index=$(this).index();
            $(this).addClass("add_style").siblings("tr").removeClass("add_style");
            $(".tsearch_guanzhu ul li").eq(index).show().siblings("").hide();
            var idnamevalue=$(this).attr("data-href");
            $(this).find("td:last-child").find("span").eq(0).off("click").click(function(e){
                e.preventDefault();
                e.stopPropagation();
                var numindex=$(this).attr("data-statu");
                if(numindex==0){
                    $(this).html("<i class='iconfont cnf_red'>&#xe655;</i>");
                    $(this).attr("data-statu",1)
                }else{
                    $(this).html("<i class='iconfont '>&#xe631;</i>");
                    $(this).attr("data-statu",0)
                }
                var status=$(this).attr("data-statu");
                var vehicleId=$(this).parents("tbody tr").attr("data-href");
                self.gunzhuAjax(status,vehicleId)

            })
            $(this).find("td:last-child").find("span").eq(1).off("click").click(function(e){
                e.preventDefault();
                e.stopPropagation();
                creatidname(idnamevalue,1)
            })
            $(this).find("td:last-child").find("span").eq(2).off("click").click(function(e){
                e.preventDefault();
                e.stopPropagation();
                creatidname(idnamevalue,2)
            })
        });
        self.vars.map.setZoom(7);
        self.vars.map.setFitView();

        function creatidname(idnamevalue,index){
            $.each(data,function(i,dom){
                if(dom.id==idnamevalue){
                    $(".tsearch_marker").show();
                    $(".tsearch_markermMenu ul li").eq(index).addClass("tsearch_menuActive").siblings("").removeClass("tsearch_menuActive")
                    $(".tsearch_markerBox").find("tsearch_markerBoxinfo").eq(index).show().siblings("").hide();
                    self.btnEventTab(dom.position,dom.id,dom.carPi);
                    self.openMarkerajax(dom.id);
                    self.opensocket("1",dom.id);
                    updateMarker(dom.position)
                    self.vars.map1.clearMap();
                    var marker1 = new AMap.Marker({
                        map: self.vars.map1 ,
                        icon: "img/icon_marker3.png",
                        position: dom.position
                    });
                }
            })
        }
    },
    btnEventTab:function(position,idname,carno){
        var self=this;
        $(".tsearch_markermMenu ul li").click(function(){
            var index=$(this).index();
            $(this).addClass("tsearch_menuActive").siblings("li").removeClass("tsearch_menuActive");
            $(".tsearch_markerBox .tsearch_markerBoxinfo").eq(index).show().siblings().hide();
            self.vars.map1.clearMap();
            if(index!=1) {
                var marker1 = new AMap.Marker({
                    map: self.vars.map1 ,
                    icon: "img/icon_marker3.png",
                    position: position
                });
                self.vars.map1.add([marker1]);
                self.vars.map1.setFitView([marker1]);
                if(index==0){
                    self.openMarkerajax(idname);
                }
                if(index==2){
                    $("#selcet1").click(function(){
                        self.vars.shipin.VehicleID=idname;
                        var num=$("#selcet1").find("option:selected").index()+1;
                        self.vars.shipin.channelIds=[num];
                        self.creatshipin(self.vars.shipin.VehicleID,num);
                    })
                }
                if(index==3){

                }
                if(index==4){
                    $("#ss_chaxun").click(function(){
                        var num=$("#selcet4").find("option:selected").index();
                        self.vars.baojing.vehicleNo=carno;
                        self.vars.baojing.alarmType=num;
                        if(index!=0){
                            self.creatbaojing(self.vars.baojing);
                        }else{
                            self.vars.baojing.alarmType="";
                            self.creatbaojing(self.vars.baojing);
                        }
                    })
                }
                if(index==5){
                    $("#ss_five").click(function(){
                        var index=$("#selcet5").find("option:selected").index();
                        var mIndex=["0x9501","0x9502","0x9503","0x9505","0x920A","0x9504","0x9801","0x9301","0x9302"];
                        self.vars.jiahu.vehicleId=idname;
                        self.vars.jiahu.commandCodeName=mIndex[index];
                        self.creatJiaohu(self.vars.jiahu)
                    })
                }

            }else {
                //self.vars.guiji.VehicleID = idname;
                $("#ss_one").click(function(){
                    self.vars.map1.clearMap();
                    self.ajaxguiji(self.vars.guiji);
                })
            }

        });
    },
    moren:function(){
        $(".tsearch_markermMenu ul li").eq(0).addClass("tsearch_menuActive").siblings("li").removeClass("tsearch_menuActive");
        $(".tsearch_markerBox .tsearch_markerBoxinfo").eq(0).show().siblings("").hide();
        $('#time1').find("input").val("");
        $('#time2').find("input").val("");
        $('#time3').find("input").val("");
        $('#time4').find("input").val("");
        $("#selcet3").siblings("input").val("通道1");
        $("#selcet4").siblings("input").val("全部");
        $("#selcet5").siblings("input").val("车辆单向监听");
    },
    searchcarbtn:function(){
        var self=this;
        $("#userCarsousuo").unbind("click");
        $("#userCarsousuo").click(function(){
            self.vars.map.clearMap();
            var value=$("#userCar").val();
            self.vars.data.vehicleNo=value;
            self.carSearch(self.vars.data);
            self.page(self.vars.data);
        })
    },
    addCircle:function(num){
        var self=this;
        var overlays=[];
        self.vars.mouseTool.circle({
            strokeColor:'#0091ea',
            strokeOpacity:1,
            strokeWeight: 2,
            fillColor:'#80d8ff',
            fillOpacity:0.4,
            strokeStyle: 'solid',
        });
        self.vars.mouseTool.on('draw',function(e){
            overlays.push(e.obj);
        });
        if(num==1) {
            self.vars.pathth="";
            AMap.event.addListener(self.vars.mouseTool, 'draw', function (e) { //添加事件
                var mpositionttr = [];
                console.log(e.obj.getPath());//获取路径/范围
                mpositionttr.push(e.obj.getPath());
                for (var i = 0; i < mpositionttr[0].length; i++) {
                    if (i != (mpositionttr[0].length - 1)) {
                        self.vars.pathth += mpositionttr[0][i].lng + "," + mpositionttr[0][i].lat + "#"
                    } else {
                        self.vars.pathth += mpositionttr[0][i].lng + "," + mpositionttr[0][i].lat+"|"
                    }
                }
                console.log(self.vars.pathth)
                self.vars.areaData.areaCode = "";
                self.vars.areaData.polygon = self.vars.pathth;
                self.carAreaSearch(self.vars.areaData)

            });
        }

    },
    creatpolygon:function(num){
        var self=this;
        self.vars.mouseTool.rectangle({
            strokeColor:'#0091ea',
            strokeOpacity:1,
            strokeWeight: 2,
            fillColor:'#80d8ff',
            fillOpacity:0.4,
            strokeStyle: 'solid',
        });
        if(num==1) {
            self.vars.path="";
            AMap.event.addListener(self.vars.mouseTool, 'draw', function (e) { //添加事件
                var mposition = [];
                mposition.push(e.obj.getPath());
                for (var i = 0; i < mposition[0].length; i++) {
                    if (i != (mposition[0].length - 1)) {
                        self.vars.path += mposition[0][i].lng + "," + mposition[0][i].lat + "#"
                    } else {
                        self.vars.path += mposition[0][i].lng + "," + mposition[0][i].lat+"|"
                    }
                };
                console.log(self.vars.path)
                self.vars.areaData.areaCode = "";
                self.vars.areaData.polygon = self.vars.path;
                console.log(self.vars.areaData)
                self.carAreaSearch(self.vars.areaData)

            });

        }
    },
    creatDrawarea:function(path){
        var self=this;
        var district = null;
        var polygons=[];
        for (var i = 0, l = polygons.length; i < l; i++) {
            polygons[i].setMap(null);
        }
        //加载行政区划插件
        if(!district){
            //实例化DistrictSearch
            var opts = {
                subdistrict: 0,
                extensions: 'all',
                level: 'district'
            };
            district = new AMap.DistrictSearch(opts);
        }
        //行政区查询
        district.search(path, function(status, result) {
            self.vars.map.remove(polygons)//清除上次结果
            polygons = [];
            var bounds = result.districtList[0].boundaries;
            if (bounds) {
                for (var i = 0, l = bounds.length; i < l; i++) {
                    //生成行政区划polygon
                    var polygon = new AMap.Polygon({
                        strokeWeight: 2,
                        path: bounds[i],
                        fillOpacity: 0.4,
                        fillColor: '#80d8ff',
                        strokeColor: '#0091ea'
                    });
                    polygons.push(polygon);
                }
            }
            self.vars.map.add(polygons)
            self.vars.map.setFitView(polygons);//视口自适应
        });
    },
    ceju:function(){
        var self=this;
        var startMarkerOptions= {
            icon: new AMap.Icon({
                size: new AMap.Size(19, 31),//图标大小
                imageSize:new AMap.Size(19, 31),
                image: "https://webapi.amap.com/theme/v1.3/markers/b/start.png"
            })
        };
        var endMarkerOptions = {
            icon: new AMap.Icon({
                size: new AMap.Size(19, 31),//图标大小
                imageSize:new AMap.Size(19, 31),
                image: "https://webapi.amap.com/theme/v1.3/markers/b/end.png"
            }),
            offset: new AMap.Pixel(-9, -31)
        };
        var midMarkerOptions = {
            icon: new AMap.Icon({
                size: new AMap.Size(19, 31),//图标大小
                imageSize:new AMap.Size(19, 31),
                image: "https://webapi.amap.com/theme/v1.3/markers/b/mid.png"
            }),
            offset: new AMap.Pixel(-9, -31)
        };
        var lineOptions = {
            strokeStyle: "solid",
            strokeColor: "#FF33FF",
            strokeOpacity: 1,
            strokeWeight: 2
        };
        var rulerOptions = {
            startMarkerOptions: startMarkerOptions,
            midMarkerOptions:midMarkerOptions,
            endMarkerOptions: endMarkerOptions,
            lineOptions: lineOptions
        };
        self.vars.ruler1 = new AMap.RangingTool(self.vars.map, rulerOptions);
    },
    btnEvent:function(){
        var self=this;
        var optionArrsou=["矩形查询","圆形查询","行政划分"];
        self.creatId("#selcet_sousuo",optionArrsou);
        var num=0;
        $(".tsearch_markerClose").click(function(){
            num+=1;
            $(this).attr("data-num",num);
            $(".tsearch_marker").hide();

        });
        $(".tsearch_headMenu ul li").click(function(){
            self.vars.map.clearMap();
            var index=$(this).index();
            $(this).addClass("ts_headActive").siblings("li").removeClass("ts_headActive");
            $(".tsearch_headbox .tsearch_headboxMain").eq(index).show().siblings().hide();
        });
        $(".tsearch_menu ul li").click(function(){
            var index=$(this).index();
            $(".tsearch_strn .tsearch_mayTable").eq(index).show().siblings("").hide();
            $(this).addClass("tsearch_menuActive").siblings("li").removeClass("tsearch_menuActive");
            $(".tsearch_box .tsearch_boxInput").eq(index).addClass("tsearch_block").siblings("").removeClass("tsearch_block");
            $(".tsearch_xingzheng").hide();
            $(".tearch_selcet .tseach-btn").show();
            if(index==1){
                $("#selcet_sousuo").siblings("input").val("矩形查询");
                $(".tearch_selcet .tseach-btn").eq(0).text("画矩形");
                $(".tearch_selcet .tseach-btn").eq(1).text("删除矩形");
                $(".tsearch_xingzheng").hide();
                self.vars.map.clearMap();
                $('#table tbody').html("");
                $(".tsearch_tableCount span").eq(0).find("em").html("");
                $(".tsearch_tableCount span").eq(1).find("em").html("");
            }else{
                self.vars.map.clearMap();
                self.vars.data.vehicleNo="";
                self.carSearch(self.vars.data)
            }
        });
        $("#selcet_sousuo").on("change",function(){
            self.vars.map.clearMap();
            var index= $(this).find("option:selected").index();
            var name = $(this).find("option:selected").val();
            if(index !=2){
                $(".tearch_selcet .tseach-btn").show();
                $(".tsearch_xingzheng").hide();
                $(".tearch_selcet .tseach-btn").eq(0).text("画"+name.substring(0,2));
                $(".tearch_selcet .tseach-btn").eq(1).text("删除"+name.substring(0,2));
            }else{
                $(".tearch_selcet .tseach-btn").hide();
                $(".tsearch_xingzheng").show();
            }
        });
        var numt=0,numn=0;
        $(".tearch_selcet .tseach-btn").eq(0).trigger("click");
        $(".tearch_selcet .tseach-btn").eq(0).click(function(){
            var value=$(this).text();
            self.vars.pathlist="";
            if(value=="画矩形"){
                numt+=1;
                self.vars.path="";
                $(".tsearch_tableCount span").eq(0).find("em").html("0");
                $(".tsearch_tableCount span").eq(1).find("em").html("0");
                self.vars.map.clearMap();
                self.creatpolygon(numt);
            }else if(value=="画圆形"){
                numn+=1;
                self.vars.pathth="";
                $(".tsearch_tableCount span").eq(0).find("em").html("0");
                $(".tsearch_tableCount span").eq(1).find("em").html("0");
                self.vars.map.clearMap();
                self.addCircle(numn);
            }
        });
        $(".tearch_selcet .tseach-btn").eq(1).trigger("click");
        $(".tearch_selcet .tseach-btn").eq(1).click(function(){
            $(".tsearch_tableCount span").eq(0).find("em").html("0");
            $(".tsearch_tableCount span").eq(1).find("em").html("0");
            self.vars.mouseTool.close(true);
            self.vars.map.clearMap();
            $('#table tbody').html("");
            $('#table1 tbody').html("");
        });
        $(".tsearch_guanzhu ul li span.tsearch_ceju").click(function(){
            self.vars.ruler1.turnOn();
        });
        $(".tsearch_guanzhu ul li span.tsearch_heart").click(function(){
            $(".page").hide();
            self.creatguanzhucheliang(self.vars.carguanzhu);
        });
        $(".tsearch_markerBox").find(".tsearch_markerBoxinfo").eq(0).find(".tsearch_footer ul li").click(function(){
            var noname=$(".tsearch_headboxMain ul li").eq(0).find("em").html();
            var noid=$(".tsearch_headboxMain ul li").eq(0).find("em").attr("data-href");
            var index=$(this).index();
            if(index==0){
                $("#tseJt").show();
                $("#phone").val("");
                $("#strart_xf").off("click").click(function(){
                    var textNum=$("#phone").val();
                    var data={};
                    data.vehicleId=noid;
                    data.vehicleNo=noname;
                    data.monitorTel=textNum
                    self.socketbase("49",data);
                    console.log("7777",data);
                    self.socket.on('Business', function(data){
                        console.log("111",data);
                        JPop.alert({msg:"下发陈功"})
                        $("#tseJt").hide();
                    });
                })
            }
            if(index==1){
                $("#tseClpz").show();
                $("#strart_xf1").click(function(){
                    var index=$("#selcet_r1").find("option:selected").index()+1;
                    var Iindex=$("#selcet_r2").find("option:selected").index()+1;
                    var data={};
                    data.vehicleId=noid;
                    data.vehicleNo=noname;
                    data.lensId=index;
                    data.size=Iindex
                    self.socketbase("50",data);
                    self.socket.on('Business', function(data){
                        console.log("133",data)
                        $("#tseClpz").hide();
                    });
                })
            }
            if(index==2){
                $("#tseSbcl").show();
                $("#strart_xf2").click(function(){
                    self.vars.datasbcx.vehicleId=noid;
                    self.vars.datasbcx.vehicleNo=noname;
                    self.socketbase("52",self.vars.datasbcx);
                    self.socket.on('Business', function(data){
                        $("#tseSbcl").hide();
                    });
                })
            }
            if(index==3) {
                $("#tseCaryj").show();
                $("#strart_xf3").click(function () {
                    self.vars.datayjjr.vehicleId = noid;
                    self.vars.datayjjr.vehicleNo = noname;
                    self.vars.datayjjr.authenicationCode = $("#tseCaryj .tantk_main_mt").eq(0).find("input").val();
                    self.vars.datayjjr.accessPointName = $("#tseCaryj .tantk_main_mt").eq(1).find("input").val();
                    self.vars.datayjjr.userName = $("#tseCaryj .tantk_main_mt").eq(2).find("input").val();
                    self.vars.datayjjr.passWord = $("#tseCaryj .tantk_main_mt").eq(3).find("input").val();
                    self.vars.datayjjr.serverIp = $("#tseCaryj .tantk_main_mt").eq(4).find("input").val();
                    self.vars.datayjjr.tcpPort = $("#tseCaryj .tantk_main_mt").eq(5).find("input").val();
                    self.vars.datayjjr.udpPort = $("#tseCaryj .tantk_main_mt").eq(6).find("input").val();
                    self.socketbase("53",self.vars.datayjjr);
                    self.socket.on('Business', function(data){
                        console.log("123",data);
                        $("#tseCaryj").hide();
                    });
                })
            }
            if(index==4){
                $("#tseCarsbxx").show();
                $("#strart_xf4").click(function () {
                    var data={};
                    data.vehicleNo=noname;
                    self.socketbase("54",data);
                    self.socket.on('Business', function(data){
                        $("#tseCarsbxx").hide();
                    });
                })
            }
            if(index==5){
                $("#tseCarsbyd").show();
            }
            if(index==6){
                $("#tseCarsbxl").show();
            }
            if(index==7){
                $("#tseCarsbw").show();
                $("#strart_xf7").click(function () {
                    var data={};
                    data.vehicleId=noid;
                    data.vehicleNo=noname;
                    data.msgPriority=$("#selcet_r1").find("option:selected").index()+1
                    data.msgContent=$("#tseCarsbw .tantk_main_mt").eq(1).find("input").val();
                    self.socketbase("51",data);
                    self.socket.on('Business', function(data){
                        $("#tseCarsbw").hide();
                    });
                })
            }
            if(index==8){
                $("#tseCarsxxgl").show();
            }

        })
        $(".close-div").click(function(){
            $("#tseJt").hide();
            $("#tseClpz").hide();
            $("#tseSbcl").hide();
            $("#tseCaryj").hide();
            $("#tseCarsbxx").hide();
            $("#tseCarsbyd").hide();
            $("#tseCarsbxl").hide();
            $("#tseCarsbw").hide();
            $("#tseCarsxxgl").hide();
        })
        $(".prinqx").click(function(){
            $("#tseJt").hide();
            $("#tseClpz").hide();
            $("#tseSbcl").hide();
            $("#tseCaryj").hide();
            $("#tseCarsbxx").hide();
            $("#tseCarsbyd").hide();
            $("#tseCarsbxl").hide();
            $("#tseCarsbw").hide();
            $("#tseCarsxxgl").hide();
        })


    },
    socketbase:function(command,data){
        var self=this;
        var conmanedtn = {
            "Command": command,
            "CommandType": "Business",
            "token":self.Authorization,
            "Body": {
                "data":data
            }
        }
        console.log("123456",JSON.stringify(conmanedtn));
        console.log("123",self.socket.io);
        self.socket.emit('Business', JSON.stringify({
            "Command": command,
            "CommandType": "Business",
            "token":self.Authorization,
            "Body": {
                "data":data
        }}));
    },
    time:function(){
        var self=this;
        $('#time1').datePicker({
            format: 'YYYY-MM-DD HH:mm',
            isRange: true,
            hide: function () {
                self.vars.guiji.StartTime=this.$input.eq(0).val();
                self.vars.guiji.EndTime=this.$input.eq(1).val();

            }
        });
        $('#time2').datePicker({
            format: 'YYYY-MM-DD HH:mm',
            isRange: true,
            hide: function () {
                self.vars.luxiang.timeStart=this.$input.eq(0).val();
                self.vars.luxiang.timeEnd=this.$input.eq(1).val();

            }
        });
        $('#time3').datePicker({
            format: 'YYYY-MM-DD HH:mm',
            isRange: true,
            hide: function () {
                self.vars.baojing.timeStart=this.$input.eq(0).val();
                self.vars.baojing.timeEnd=this.$input.eq(1).val();

            }
        });
        $('#time4').datePicker({
            format: 'YYYY-MM-DD HH:mm',
            isRange: true,
            hide: function () {
                self.vars.jiahu.timeStart=this.$input.eq(0).val();
                self.vars.jiahu.timeEnd=this.$input.eq(1).val();

            }
        });
        $('#time_r1').datePicker({
            format: 'YYYY-MM-DD HH:mm',
            isRange: true,
            hide: function () {
                self.vars.datasbcx.startTime=this.$input.eq(0).val();
                self.vars.datasbcx.endTime=this.$input.eq(1).val();

            }
        });
        $("#time_js").datePicker({
            format: 'YYYY-MM-DD HH:mm:ss',
            hide: function () {
                self.vars.datayjjr.endTime=this.$input.val();

            }
        });
    },
    selectedValue:function(){
        var self=this;
        var optionArr=["通道1(音频/视频,驾驶员)","通道2(音频/视频,车辆正前方)","通道3(音频/视频,车前门)","通道4(音频/视频,车厢前部)"];
        self.creatId("#selcet1",optionArr);
        self.creatId("#selcet2",optionArr);
        self.creatId("#selcet3",optionArr);

        var optionArr4=["全部","一级","二级"];
        self.creatId("#selcet4",optionArr4);
        var optionArr5=["车辆单向监听","车辆拍照","车辆文本下发","车辆应急接入","上报驾驶员身份信息","上报车辆行驶路线","车辆视频监控","查岗请求","平台间报文","上报行驶记录仪信息","上报车辆电子运单"];
        self.creatId("#selcet5",optionArr5);
        var optionArr6=["省级平台下发","部级平台下发","下级平台上报"];
        self.creatId("#selcet6",optionArr6);

        var optionjt=["摄像头1","摄像头2","摄像头3","摄像头4"];
        self.creatId("#selcet_r1",optionjt)
        var optionjt1=["320*240","640*480","800*600","1240*768","176*144(QCIF)","704*288(CIF)","704*288(HALFD)"];
        self.creatId("#selcet_r2",optionjt1)
        var optionjt2=["紧急","一般"];
        self.creatId("#selcet_r3",optionjt2)
    },
    creatId:function(id,optionArr){
        $(id).html();
        var str="";
        $.each(optionArr,function (i) {
            str+="<option value='"+optionArr[i]+"'>"+optionArr[i]+"</option>"
        });
        $(id).html(str);
        $(id).comboSelect();
    },

}

$(function(){
    common.initCatalogueMagePage();
});